import java.util.Scanner;

public class ClientScanner {
    public static final Scanner sc = new Scanner(System.in);

    public void closeScanner() {
        sc.close();
    }

    public static String inputJudge(String regex) {

        String input = sc.nextLine();
        while ( !input.matches(regex) ) {
            System.out.println("输入不符合格式要求"+"("+regex+")");
            input = sc.nextLine();
        }
        return input;
    }

    public static String[] buildNewUserInfo(String uses) {

        System.out.print("请输入要"+uses+"的用户名和密码:");
        String input;
        input = inputJudge("([\\w]+ [\\S]+)|([\\w]+)");

        String[] info = new String[2];

        if (input.matches("[\\w]+")) {
            info[0] = input;
            System.out.print("请输入密码:");
            input = inputJudge("[\\S]+");
            info[1] = input;
        }
        else {
            info = input.split(" ", 2);
        }
        return info;
    }
}
